using System.Data.Entity.Migrations;

namespace YiCheap.Data.Migrations
{
    public partial class init1 : DbMigration
    {
        public override void Up()
        {
            DropForeignKey("dbo.Shops", "ProductVariant_Id", "dbo.ProductVariants");
            DropIndex("dbo.Shops", new[] { "ProductVariant_Id" });
            CreateTable(
                "dbo.ProductVariantShops",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ShopId = c.Int(nullable: false),
                        ProductVariantId = c.Int(nullable: false),
                        DisplayOrder = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Shops", t => t.ShopId, cascadeDelete: true)
                .ForeignKey("dbo.ProductVariants", t => t.ProductVariantId, cascadeDelete: true)
                .Index(t => t.ShopId)
                .Index(t => t.ProductVariantId);
            
            DropColumn("dbo.Shops", "ProductVariant_Id");
        }
        
        public override void Down()
        {
            AddColumn("dbo.Shops", "ProductVariant_Id", c => c.Int());
            DropIndex("dbo.ProductVariantShops", new[] { "ProductVariantId" });
            DropIndex("dbo.ProductVariantShops", new[] { "ShopId" });
            DropForeignKey("dbo.ProductVariantShops", "ProductVariantId", "dbo.ProductVariants");
            DropForeignKey("dbo.ProductVariantShops", "ShopId", "dbo.Shops");
            DropTable("dbo.ProductVariantShops");
            CreateIndex("dbo.Shops", "ProductVariant_Id");
            AddForeignKey("dbo.Shops", "ProductVariant_Id", "dbo.ProductVariants", "Id");
        }
    }
}
